﻿using Microsoft.AspNetCore.Mvc;
using SeckillService.Services;
using SeckillService.Services.Dtos;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;

namespace SeckillService.Controllers;

[Route("api/seckill/[action]")]
public class SeckillController : AbpController, ISeckillService
{
    public ISeckillService  seckillService { get; set; }

    public SeckillController()
    {

    }

    [HttpPost]
    public async Task<SeckillDto> CreateAsync(SeckillDto input)
    {
        return await seckillService.CreateAsync(input);
    }

    [HttpDelete]
    public async Task DeleteAsync(Guid id)
    {
        await seckillService.DeleteAsync(id);
    }

    [HttpGet]
    public async Task<SeckillDto> GetAsync(Guid id)
    {
        return await seckillService.GetAsync(id);
    }

    [HttpPost]
    public async Task<PagedResultDto<SeckillDto>> GetListAsync(PagedAndSortedResultRequestDto input)
    {
        return await seckillService.GetListAsync(input);
    }

    [HttpPut]
    public async Task<SeckillDto> UpdateAsync(Guid id, SeckillDto input)
    {
        return await seckillService.UpdateAsync(id, input);
    }

    /// <summary>
    /// 秒杀
    /// </summary>
    /// <param name="SeckillId"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    [HttpGet]
    public async Task<List<SeckillProductDto>> GetSeckillProductsAsync(Guid SeckillId)
    {
        return await seckillService.GetSeckillProductsAsync(SeckillId);
    }

    /// <summary>
    /// 秒杀商品详情页
    /// </summary>
    /// <param name="SeckillProductId"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    [HttpGet]
    public async Task<SeckillProductDto> GetSeckillProductAsync(Guid SeckillProductId)
    {
        return await seckillService.GetSeckillProductAsync(SeckillProductId);
    }

    /// <summary>
    /// 修改秒杀商品库存
    /// </summary>
    /// <param name="updateSeckillProductStockDto"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    [HttpPut]
    public async Task UpdateSeckillProductStockAsync(UpdateSeckillProductStockDto updateSeckillProductStockDto)
    {
        await seckillService.UpdateSeckillProductStockAsync(updateSeckillProductStockDto);
    }
}
